<?php

namespace Home\Controller;

/**
 * Description of CustomerController.class控制器实例
 *
 * @author zhangzhen
 * @date 2017-02-14
 */
class CustomerController extends ParentController {

    protected function _initialize() {
    	parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();
    }
    /**
     * 获取客栈客人信息
     * @modify zhangzhen 2017-02-14    创建
     */
    public function customer() {
        $param = I('post.');

        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'keys' => 'notempty',
            'currentPage' => 'notempty,natureNumber',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $startDate = $param['startDate'];
        $startDate = empty($startDate) ? date('Y-m-01') : $startDate;
        $endDate = $param['endDate'];
        $endDate = empty($endDate) ? date('Y-m-d H:i:s') : $endDate . ' 23:59:59';

        $startTime = strtotime($startDate);
        $endTime = strtotime($endDate);
        // 最多只能查询30天
        if (getTimeDiff($startTime, $endTime, 'day') >= 30) {
            $endDate = date('Y-m-d H:i:s', strtotime('+30 days', $startTime));
        }

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        // 获取信息
        $keys = isset($param['keys']) ? $param['keys'] : null;
        $pageIndex = isset($param['currentPage']) ? $param['currentPage'] : 1;

        $customerLogic = A('Common/Customer', 'Logic');
        $customerInfos = $customerLogic->getCustomerInfos($hotelId, $keys, $pageIndex, C('PAGE_SIZE'), null, $startDate, $endDate, 1);

        // 返回查询数据
        $customerInfos['searchData'] = array(
            'startDate' =>  date('Y-m-d', $startTime),
            'endDate' =>  date('Y-m-d', $endTime),
            'keys' =>  is_null($keys) ? '' : $keys,
        );

        returnJson(200, 200, $customerInfos);
    }

     /**
     * 会员信息
     * @modify zhangzhen 2017-02-16    创建
     */
    public function vip() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'mobile' => 'notempty',
            'currentPage' => 'notempty,natureNumber',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        // 获取信息
        $mobile = isset($param['mobile']) ? $param['mobile'] : null;
        $vipInfoId = isset($param['vipInfoId']) ? $param['vipInfoId'] : null;
        $allHotel = isset($param['allHotel']) ? $param['allHotel'] : null;
        $pageIndex = isset($param['currentPage']) ? $param['currentPage'] : 1;

        $customerLogic = A('Common/Customer', 'Logic');

        $customerInfos = $customerLogic->getVipInfos($hotelId, $mobile, $vipInfoId, $allHotel, $pageIndex, C('PAGE_SIZE'), null);
        returnJson(200, 200, $customerInfos);
    }
    /**
     * 添加会员
     * @modify zhangzhen 2017-02-16    创建
     * @modify wenhui 2017-05-04 增加国际手机检验
     */
    public function addVip() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'name' => 'notnull,notempty,nameLength20',
            'mobile' => 'notnull,notempty',
            'vipInfoId' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $param['areaCode'] = isset($param['areaCode']) ? $param['areaCode'] : '86';
        $mobile = $param['mobile'];
        $this->ajaxValidateReturn($this->validateUtil, $mobile, 'globalMobile',
                    array('globalMobile' => array('function', 'checkGlobalMobile,' . $param['areaCode'], '403,130,error'),
                ));

        $hotelId = $param['hotel'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }
        if(!empty($param['identity'])){
            $validateRule = array(
                'identity' => 'IDCard',
            );
            $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
            if (empty($validatePass)) {
                return;
            }
        }
        $customerLogic = A('Common/Customer', 'Logic');
        $result = $customerLogic->addVip($param);
       
        if($result){
            returnJson(200, 200);
        }
        else{
            returnJson(500, 508);
        }
        
    }
    /**
     * 查看详情会员
     * @modify zhangzhen 2017-02-16    创建
     */
    public function setVip() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipUserId' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }
        $customerLogic = A('Common/Customer', 'Logic');
        $result = $customerLogic->setVip($param['hotel'], $param['vipUserId']);
       
        if($result){
            returnJson(200, 200,$result);
        }
        else{
            returnJson(500, 512);
        }
        
    }
    /**
     * 修改会员
     * @modify zhangzhen 2017-02-17    创建
     * @modify wenhui 2017-05-04 增加国际手机检验
     */
    public function editVip() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipUserId' => 'notnull,notempty,id',
            'name' => 'notnull,notempty,nameLength20',
            'mobile' => 'notnull,notempty',
            'vipInfoId' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        if(!empty($param['identity'])){
            $validateRule = array(
                'identity' => 'IDCard',
            );
            $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
            if (empty($validatePass)) {
                return;
            }
        }

        $param['areaCode'] = isset($param['areaCode']) ? $param['areaCode'] : '86';
        $mobile = $param['mobile'];

        $this->ajaxValidateReturn($this->validateUtil, $mobile, 'globalMobile',
                    array('globalMobile' => array('function', 'checkGlobalMobile,' . $param['areaCode'], '403,130,error'),
                ));

        $hotelId = $param['hotel'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }
        $customerLogic = A('Common/Customer', 'Logic');
        $result = $customerLogic->editVip($param);
        returnJson(200, 200, $result);
       
        if($result){
            returnJson(200, 200);
        }
        else{
            returnJson(500, 509);
        }
        
    }
    /**
     * 会员规则初始化
     * @modify zhangzhen 2017-02-15    创建
     */
    public function vipInit() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'level' => 'notempty,natureNumber',
            'share' => 'notempty,natureNumber',
            'discount' => 'notempty,natureNumber',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = getUserId();
        $hotelId = $param['hotel'];
        //检查是否超级管理员
        $adminAuthorityLogic = A('Common/AdminAuthority','Logic');
        $hasRight = $adminAuthorityLogic->checkIsAdmin($userId,$hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

    	$vipInitModel = D('VipInit');
        $vipInitInfo = $vipInitModel->addInfo($userId, $param['level'], $param['share'], $param['discount']); 
    	returnJson(200, 200, 'success');
    }
    /**
     * 添加会员等级
     * @modify zhangzhen 2017-02-15    创建
     */
    public function addVipLevel() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'name' => 'notempty,nameLength15',
            'auto' => 'notempty,natureNumber',
            'discount' => 'notempty,natureNumber',
            'discountRule' => 'notnull,notempty',
            'level' => 'notempty,natureNumber',
            'levelRule' => 'notnull,notempty',
            'share' => 'notempty,natureNumber',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

    	$customerLogic = A('Common/Customer', 'Logic');
        $result = $customerLogic->addVipLevel($param['name'], $hotelId, $param['auto'], $param['level'], $param['levelRule'], $param['discount'], $param['discountRule'], $param['share']);
        
    	if($result){
    		returnJson(200, 200, [
	    		'id'=>$result,
	    		'name'=>$param['name'],
	    	]);
        }else{
        	returnJson(500, 508);
        }
    }
    /**
     * 查看会员信息详细内容
     * @modify zhangzhen 2017-02-16    创建
     */
    public function setVipLevel() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipInfoId' => 'notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        $vipInfoId = $param['vipInfoId'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

    	$vipInfoModel = D('VipInfo');
        $vipLevelInfo = $vipInfoModel->getInfoById($vipInfoId); 
    	returnJson(200, 200, $vipLevelInfo);
    }
    /**
     * 修改会员信息详细
     * @modify zhangzhen 2017-02-16    创建
     */
    public function editVipLevel() {
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipInfoId' => 'notempty,id',
            'name' => 'notempty,nameLength15',
            'auto' => 'notempty,natureNumber',
            'discount' => 'notempty,natureNumber',
            'discountRule' => 'notnull,notempty',
            'level' => 'notempty,natureNumber',
            'levelRule' => 'notnull,notempty',
            'share' => 'notempty,natureNumber',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        $vipInfoId = $param['vipInfoId'];
        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

    	$customerLogic = A('Common/Customer', 'Logic');
        $result = $customerLogic->editVipLevel($vipInfoId, $param['name'], $hotelId, $param['auto'], $param['level'], $param['levelRule'], $param['discount'], $param['discountRule'], $param['share']);

        if($result){
    		returnJson(200, 200,  [
	    		'id'=>$vipInfoId,
	    		'name'=>$param['name'],
	    	]);
        }else{
        	returnJson(500, 509);
        }
    }
    /**
     * 下订单时查询号码
     * @modify zhangzhen 2017-02-20    创建
     */
    public function searchMobile(){
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'mobile' => 'notempty',
            'areaCode' => 'notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $areaCode = isset($param['areaCode']) ? $param['areaCode'] : '86';
        $vipUserModel = D('VipUser');
        $vipUserInfo = $vipUserModel->getInfoLikeMobile($param['hotel'], $param['mobile'], $areaCode);
        $vipUserCardModel = D('VipUserCard');
        $vipuserId = array_column($vipUserInfo, 'id');
        $userCardInfo = $vipUserCardModel->field('vipuser_id,price')->where(array('vipuser_id' => array('in', $vipuserId)))->select();
        $userCardInfo = getArrayValueAsIndex($userCardInfo, 'vipuser_id');

        foreach ($vipUserInfo as $key => &$vipUserItem) {
            $vipUserItem['cardPrice'] = isset($userCardInfo[$vipUserItem['id']]['price']) ? $userCardInfo[$vipUserItem['id']]['price'] : '0.00';
        }
        unset($vipUserItem);

        returnJson(200, 200, $vipUserInfo); 
    }
    /**
     * 下订单时查询会员详情
     * @modify zhangzhen 2017-02-20    创建
     */
    public function vipInfo(){
    	$param = I('post.');
    	$validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipUserId' => 'notempty,id',
            'vipInfoId' => 'notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        $vipUserId = $param['vipUserId'];
        $vipInfoId = $param['vipInfoId'];
        $customerLogic = A('Common/Customer', 'Logic');
        $vipInfos = $customerLogic->getVipOrderInfo($hotelId, $vipUserId, $vipInfoId);
        returnJson(200, 200, $vipInfos); 
    }

    /**
     * 会员卡充值
     * @modify wenhui 2017-12-06    创建
     */
    public function setVipUserCard(){
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipUserId' => 'notempty,id',
            'cardPrice' => 'notempty,notnull,decimal8_2',
            'payType' => 'notempty,notnull,id',
            'remark' => 'nameLength50',
            'verify' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验图片验证码
        $verify = $param['verify'];
        if (empty(checkVcode($verify))) {
            returnJson(403, 201);
            return;
        }

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        $vipUserId = $param['vipUserId'];
        $cardPrice = $param['cardPrice'];
        $payType = $param['payType'];
        $remark = $param['remark'];
        $customerLogic = A('Common/Customer', 'Logic');

        $vipCardInfos = $customerLogic->setVipUserCard($hotelId, $vipUserId, $cardPrice, $payType, $remark);
        returnJson(200, 200, $vipCardInfos);
    }

    /**
     * 获取会员卡记录
     * @modify wenhui 2017-12-06    创建
     */
    public function getVipCardRecord(){
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'vipUserId' => 'notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        $vipUserId = $param['vipUserId'];
        $customerLogic = A('Common/Customer', 'Logic');
        $vipCardRecordInfos = $customerLogic->getVipCardRecord($hotelId, $vipUserId);
        returnJson(200, 200, $vipCardRecordInfos);
    }

    /**
     * 根据条件筛选到订单数据到Excel
     * @modify wenhui 2017-07-03
     */
    public function exportCustomerList() {
        $param = I('get.');

        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $adminHotelModel = D('AdminHotel');
        $userId = getUserId();
        $adminHotel = $adminHotelModel->getInfoByAdminHotel($userId, $param['hotel']);
        //不是客栈创建人员，需要检查操作权限
        $isAdmin = true;
        if ($adminHotel['role'] != HOTEL_ROLE_OWNER) {
            $isAdmin = false;
        }

        // 检查是否有查看 身份证信息权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $canSeeID = $adminAuthorityLogic->check($param['hotel'], null, AUTHORITY_ID_INFO_BLOCK);
        if ($canSeeID && !$isAdmin) {
            returnJson(403, 202, 'error');
            return;
        }

        $startDate = $param['startDate'];
        $startDate = empty($startDate) ? date('Y-m-d') : $startDate;
        $endDate = $param['endDate'];
        $endDate = empty($endDate) ? date('Y-m-d H:i:s') : $endDate . ' 23:59:59';

        $startTime = strtotime($startDate);
        $endTime = strtotime($endDate);
        // 最多只能查询半年
        if (getTimeDiff($startTime, $endTime, 'day') >= 180) {
            $startDate = date('Y-m-1');
            $endDate = date('Y-m-d H:i:s');
        }

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 查询客栈数据
        $hotelEntityModel = D('HotelEntity');
        $hotelEntity = $hotelEntityModel->getInfo($hotelId);

        // 检查权限
        Vendor('phpExcel.PHPExcel');
        $phpExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);

        // 获取信息
        $keys = isset($param['keys']) && !empty($param['keys']) ? $param['keys'] : null;

        $customerLogic = A('Common/Customer', 'Logic');
        $customerInfos = $customerLogic->getCustomerInfos($hotelId, null, null, null, null, $startDate, $endDate, 2);
        $customerInfos = $customerInfos['item'];
        // 输出文件名
        $customerListString = '';
        $phpExcel->setActiveSheetIndex(0);
        // 单元格宽度
        $phpExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
        $phpExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);

        switch (LANG_SET) {
            case 'en_us':
                $customerListString .= 'Customer list';
                // 设置导出Excel标题
                $phpExcel->getActiveSheet()->setCellValue('A1', 'Name');
                $phpExcel->getActiveSheet()->setCellValue('B1', 'Gender');
                $phpExcel->getActiveSheet()->setCellValue('C1', 'Nationalities');
                $phpExcel->getActiveSheet()->setCellValue('D1', 'ID');
                $phpExcel->getActiveSheet()->setCellValue('E1', 'Address');
                $phpExcel->getActiveSheet()->setCellValue('F1', 'Mobile');
                $phpExcel->getActiveSheet()->setCellValue('G1', 'Check in times');
                $phpExcel->getActiveSheet()->setCellValue('H1', 'Check out times');
                $phpExcel->getActiveSheet()->setCellValue('I1', 'Stay long');
                $phpExcel->getActiveSheet()->setCellValue('J1', 'Room');
                break;
            case 'zh_tw':
                $customerListString .= '客人清單';
                // 设置导出Excel标题
                $phpExcel->getActiveSheet()->setCellValue('A1', '姓名');
                $phpExcel->getActiveSheet()->setCellValue('B1', '性别');
                $phpExcel->getActiveSheet()->setCellValue('C1', '民族');
                $phpExcel->getActiveSheet()->setCellValue('D1', '證件號碼');
                $phpExcel->getActiveSheet()->setCellValue('E1', '住址');
                $phpExcel->getActiveSheet()->setCellValue('F1', '手機號');
                $phpExcel->getActiveSheet()->setCellValue('G1', '入住日期');
                $phpExcel->getActiveSheet()->setCellValue('H1', '退房日期');
                $phpExcel->getActiveSheet()->setCellValue('I1', '入住時長');
                $phpExcel->getActiveSheet()->setCellValue('J1', '入住房間');
                break;
            default:
                $customerListString .= '客人列表';
                // 设置导出Excel标题
                $phpExcel->getActiveSheet()->setCellValue('A1', '姓名');
                $phpExcel->getActiveSheet()->setCellValue('B1', '性别');
                $phpExcel->getActiveSheet()->setCellValue('C1', '民族');
                $phpExcel->getActiveSheet()->setCellValue('D1', '证件号码');
                $phpExcel->getActiveSheet()->setCellValue('E1', '住址');
                $phpExcel->getActiveSheet()->setCellValue('F1', '手机号');
                $phpExcel->getActiveSheet()->setCellValue('G1', '入住日期');
                $phpExcel->getActiveSheet()->setCellValue('H1', '退房日期');
                $phpExcel->getActiveSheet()->setCellValue('I1', '入住时长');
                $phpExcel->getActiveSheet()->setCellValue('J1', '入住房间');
                break;
        }
        $outputFileName = $hotelEntity['name'] . date("Y.m.d") . $customerListString;

        $gender = [
            'zh_cn' => ['男', '女'],
            'zh_tw' => ['男', '女'],
            'en_us' => ['male', 'woman'],
        ];
        // 数据输出格式处理
        foreach ($customerInfos as $key => &$customerItem) {
            if ($customerItem['idsex'] == 1) {
                $customerItem['idsex'] = $gender[LANG_SET][0];
            } else if (!empty($customerItem['idsex']) && $customerItem['idsex'] == 0) {
                $customerItem['idsex'] = $gender[LANG_SET][1];
            }
            $areaCode = !empty($customerItem['mobile']) ? '+' . $customerItem['areaCode'] : '';
            $customerItem['night'] = isset($customerItem['hour']) && $customerItem['hour'] != 0 ? $customerItem['hour'] : $customerItem['night'];

            $phpExcel->getActiveSheet()->setCellValueExplicit('A' . ($key + 2), $customerItem['name'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('B' . ($key + 2), $customerItem['idsex'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('C' . ($key + 2), $customerItem['idnation'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('D' . ($key + 2), $customerItem['identity'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('E' . ($key + 2), $customerItem['idaddress'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('F' . ($key + 2), $areaCode . ' ' . $customerItem['mobile'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('G' . ($key + 2), $customerItem['startTime'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('H' . ($key + 2), $customerItem['checkoutTime'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('I' . ($key + 2), $customerItem['night'], \PHPExcel_Cell_DataType::TYPE_STRING);
            $phpExcel->getActiveSheet()->setCellValueExplicit('J' . ($key + 2), $customerItem['checkInRoomName'], \PHPExcel_Cell_DataType::TYPE_STRING);
        }        
        //调用输出excel
        phpExcelOutput($objWriter, $outputFileName);
    }
}
